package com.fyakm.daodejing.simple.stockTest.util;

import com.fyakm.daodejing.simple.stockTest.domain.StockHistory;

import java.io.File;
import java.util.List;



// 股票工具类
public class StockUtil {

    private static String dir = "C:\\Users\\22603\\Desktop\\temp\\A股数据";

    public static StockTradingUtils.TradingResult  testStock(String stockCode,String beginDate,String endDate){

        // 读取股票数据
        File stockFile = new File(dir, stockCode + ".csv");
        if (!stockFile.exists()) {
            System.out.println("未找到股票代码为 " + stockCode + " 的数据文件！");
            return null;
        }

        List<StockHistory> stockHistory = CsvReader.readStockHistoryFromCsv(stockFile.getAbsolutePath());
        stockHistory = StockHistory.subListByDate(stockHistory, beginDate, endDate);

        // 模拟交易并计算盈利
        Integer initialAmount = 1000000; // 投资人初始金额
        StockTradingUtils.TradingResult result = StockTradingUtils.simulateTrading(stockCode, initialAmount, stockHistory);
        return result;
    }

}